package Lambda表达式;

import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collector;
import java.util.stream.Stream;

import javaaaaaaaaa.Person;

public class 使用Lambdas和Streams {

	public static void main(String[] args) {
		List<Person> javaProgrammers = new ArrayList<Person>() {
			{
				add(new Person("Elsdon", "Jaycob", "Java programmer", "male", 43, 2000));
				add(new Person("Tamsen", "Brittany", "Java programmer", "female", 23, 1500));
				add(new Person("Floyd", "Donny", "Java programmer", "male", 33, 1800));
				add(new Person("Sindy", "Jonie", "Java programmer", "female", 32, 1600));
				add(new Person("Vere", "Hervey", "Java programmer", "male", 22, 1200));
				add(new Person("Maude", "Jaimie", "Java programmer", "female", 27, 1900));
				add(new Person("Shawn", "Randall", "Java programmer", "male", 30, 2300));
				add(new Person("Jayden", "Corrina", "Java programmer", "female", 35, 1700));
				add(new Person("Palmer", "Dene", "Java programmer", "male", 33, 2000));
				add(new Person("Addison", "Pam", "Java programmer", "female", 34, 1300));
			}
		};

		List<Person> phpProgrammers = new ArrayList<Person>() {
			{
				add(new Person("Jarrod", "Pace", "PHP programmer", "male", 34, 1550));
				add(new Person("Clarette", "Cicely", "PHP programmer", "female", 23, 1200));
				add(new Person("Victor", "Channing", "PHP programmer", "male", 32, 1600));
				add(new Person("Tori", "Sheryl", "PHP programmer", "female", 21, 1000));
				add(new Person("Osborne", "Shad", "PHP programmer", "male", 32, 1100));
				add(new Person("Rosalind", "Layla", "PHP programmer", "female", 25, 1300));
				add(new Person("Fraser", "Hewie", "PHP programmer", "male", 36, 1100));
				add(new Person("Quinn", "Tamara", "PHP programmer", "female", 21, 1000));
				add(new Person("Alvin", "Lance", "PHP programmer", "male", 38, 1600));
				add(new Person("Evonne", "Shari", "PHP programmer", "female", 40, 1800));
			}
		};

		// javaProgrammers.forEach((p)->System.out.printf("%s %s; ",
		// p.getFirstName(), p.getLastName()));
		Consumer<Person> giveRaise = e -> e.setSalary(e.getSalary() / 100 * 5 + e.getSalary());
		javaProgrammers.forEach(giveRaise);

		// System.out.println("下面是月薪超过 $1,400 的PHP程序员:");
		// 过滤器filter()
		// phpProgrammers.stream().filter((p) -> (p.getSalary() >
		// 1400)).forEach((p) -> System.out.printf("%s %s; ", p.getFirstName(),
		// p.getLastName()));

		// 使用limit方法,可以限制结果集的个数:
		// javaProgrammers.stream().limit(3).forEach(System.out::println);

		// System.out.println("根据 name 排序,并显示前5个 Java programmers:");
		// Stream<Person> sPersons = javaProgrammers.stream().sorted((p1, p2) ->
		// (p1.getFirstName().compareTo(p1.getFirstName()))).limit(4);
		// sPersons.forEach((a)->(System.out.println(a.getFirstName())));

		// min和max方法
		Person person = javaProgrammers.stream().min((p1, p2) -> (p1.getSalary() - p2.getSalary())).get();
		Person person2 = javaProgrammers.stream().max((p1, p2) -> (p1.getSalary() - p2.getSalary())).get();
		System.out.println(person2.getFirstName());
		
		
	}
}
